package com.blue.Impl.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.blue.common.constant.CommonConstant;
import com.blue.common.utils.ThreadLocalUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.blue.mapper.system.MessageMapper;
import com.blue.po.system.MessagePO;
import com.blue.service.system.IMessageService;

import java.util.HashMap;
import java.util.Map;


@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, MessagePO> implements IMessageService {

    @Override
    public Map<String, Long> unReadCount() {
        long sysMessageCount = this.count(new LambdaQueryWrapper<MessagePO>()
                .eq(MessagePO::getMsgStatus, CommonConstant.UNREAD)
                .eq(MessagePO::getMsgType, CommonConstant.SYS_MESSAGE)
                .eq(MessagePO::getRecipient, ThreadLocalUtils.getLoginUserInfo().getUserId()));
        long messageCount = this.count(new LambdaQueryWrapper<MessagePO>()
                .eq(MessagePO::getMsgStatus, CommonConstant.UNREAD)
                .eq(MessagePO::getMsgType, CommonConstant.MESSAGE)
                .eq(MessagePO::getRecipient, ThreadLocalUtils.getLoginUserInfo().getUserId()));
        long todoCount = this.count(new LambdaQueryWrapper<MessagePO>()
                .eq(MessagePO::getMsgStatus, CommonConstant.UNREAD)
                .eq(MessagePO::getMsgType, CommonConstant.TODO)
                .eq(MessagePO::getRecipient, ThreadLocalUtils.getLoginUserInfo().getUserId()));
        long sum = sysMessageCount + messageCount + todoCount;
        Map<String, Long> map = new HashMap<>();
        map.put("sysMessageCount", sysMessageCount);
        map.put("messageCount", messageCount);
        map.put("todoCount", todoCount);
        map.put("sum", sum);
        return map;
    }
}
